package com.xiaoma.myaudience.biz.util;

import android.view.animation.Animation;
import android.view.animation.Transformation;

public class NeteaseTraslateAni extends Animation {
	private int mFromX;
	private int mToX;
	private int mFromY;
	private int mToY;
	private float mFromAlpha;
	private float mToAlpha;

	/**
	 * 
	 * @param moveFromRect
	 * @param moveToRect
	 * @param alphaFrom
	 * @param alphaTo
	 */
	public NeteaseTraslateAni(int fromX, int toX, int fromY, int toY, int fromAlpha, int toAlpha){
		mFromX = fromX;
		mToX = toX;
		mFromY = fromY;
		mToY = toY;
		mFromAlpha = fromAlpha;
		mToAlpha = toAlpha;
		
	}

	/**
	 * @see android.view.animation.Animation#applyTransformation(float,
	 *      android.view.animation.Transformation)
	 */
	protected void
			applyTransformation(float interpolatedTime, Transformation t) {
//		float sTo = interpolatedTime;
//		final Matrix matrix = t.getMatrix();
//		
//		float dx = (1.f - sTo) * (mToX - mFromX);
//		float dy = (1.f - sTo) * (mToY - mFromY);
//		
//		matrix.postTranslate(dx, dy);
		
//		t.setAlpha(mFromAlpha + sTo * (mToAlpha - mFromAlpha));
		
		float dx = mFromX;
        float dy = mFromY;
        int flag = 0;
        if (mFromX != mToX) {
        	flag ++;
            dx = mFromX + ((mToX - mFromX) * interpolatedTime);
        }
        if (mFromY != mToY) {
        	flag ++;
            dy = mFromY + ((mToY - mFromY) * interpolatedTime);
        }
        if(flag > 0)
        	t.getMatrix().postTranslate(dx, dy);
        
        if(mToAlpha - mFromAlpha != 0){
	        final float alpha = mFromAlpha;
	        t.setAlpha(alpha + ((mToAlpha - alpha) * interpolatedTime));
        }
        
	}
}
